package cn.cnsy123.blog.application.config;

import cn.cnsy123.blog.application.encoder.PasswordEncoder;
import cn.cnsy123.blog.application.encoder.strategy.Md5PasswordStrategy;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * @author yangpengfei
 * @description 数据校验相关配置
 * @date 2019-10-14 16-51-44
 */
@Configuration
public class ValidatorConfig {


    @Bean
    public Validator validator(){
        ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )
                .configure()
                .failFast( true )
                .buildValidatorFactory();
        Validator validator = validatorFactory.getValidator();
        return validator;
    }


    @Bean
    @Primary
    public PasswordEncoder passwordEncoder(){
        return new Md5PasswordStrategy();
    }

}
